import QtQuick 1.1

Rectangle {
    id: board
    color: "darkgreen"
    width: 360
    height: 360

    property variant figuresArr: [
       [[0,0,0,0],
        [0,0,0,0],
        [1,2,3,4],
        [0,0,0,0]],

       [[0,0,0,0],
        [0,0,0,0],
        [1,2,3,4],
        [0,3,2,0]],

       [[0,0,0,0],
        [0,1,4,0],
        [0,2,3,0],
        [0,0,0,0]],

       [[0,1,0,0],
        [0,4,0,0],
        [0,2,0,0],
        [0,3,4,0]],

       [[0,0,1,0],
        [0,0,4,0],
        [0,0,3,0],
        [0,4,2,0]]
    ]

    function createFigure(){
        var component = Qt.createComponent("figure.qml");
        var cellsX = 10;
        var cellsY = 20;
        var aperture = 4;
        var startingX = (board.width - board.width / cellsX * aperture) / 2;
        var figure = component.createObject(board, {
                                            x:startingX,
                                            y:0,
                                            boardWidth: board.width,
                                            boardHeight: board.height,
                                            boardSizeX: cellsX,
                                            boardSizeY: cellsY,
                                            control: control,
                                            bgrndColor : board.color,
                                            figPattern : figuresArr[0],
                                            velocity: 50,
                                            repeatRate: 25
                                        });
        figure.reachedBottom.connect(createFigure);
        figure.endTheGame.connect(gameOver);
    }

    function gameOver(){
        console.log("game over");
    }

    Component.onCompleted:{
        createFigure();
    }

    MouseArea{
        id: control
        anchors.fill: parent
    }
}
